<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>嵌套路由</title>
		<script src="https://unpkg.com/vue/dist/vue.js"></script>
		<script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
	</head>
	<body>
		<div id="app">
			<p>
				<router-link to="/user/foo">/user/foo</router-link>
				<router-link to="/user/foo/one">/user/foo/one</router-link>
				<router-link to="/user/foo/two">/user/foo/two</router-link>
			</p>
			<router-view></router-view>
		</div>
	</body>
	<script type="text/javascript">
		const User = {
			template:`
			    <div class="user">
			      <h2>User {{$route.params.id}} </h2>
			      <router-view></router-view>
			    </div>
			`
		}
		//定义路由组件
		const UserHome = {template:'<div>Home</div>'}
		const UserOne = {template:'<div>one</div>'}
		const UserTwo ={template:'<div>two</div>'}
		//定义路由 创建路由实例
		const router = new VueRouter({
			routes:[
			    {path:'/user/:id',component:User,
			        children:[
			            {path:'',component:UserHome},
			            {path:'one',component:UserOne},
			            {path:'two',component:UserTwo}
			        ]
			    }
			]
		})
		//创建和挂载根实例
		const app = new Vue({router}).$mount('#app')
	</script>
</html>
